package cn.dnui_zjq823.dnuifood_16110100823.model;

import cn.dnui_zjq823.dnuifood_16110100823.bean.ResultBean;
import cn.dnui_zjq823.dnuifood_16110100823.bean.UserBean;
import cn.dnui_zjq823.dnuifood_16110100823.iface.UserIface;
import cn.dnui_zjq823.dnuifood_16110100823.listener.onRetrofitListener;
import cn.dnui_zjq823.dnuifood_16110100823.service.UserService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by dell on 2018/10/15.
 */

public class UserModel extends BaseModel implements UserIface {
    private UserService service;
    @Override
    public void login(String username, String userpass, final onRetrofitListener listener) {
        service=retrofit.create(UserService.class);
        Call<UserBean> call=service.doLogin(username,userpass);
        bindCallback(call,listener,1);
//        call.enqueue(new Callback<UserBean>() {
//            @Override
//            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
//                if (response.body()!=null)
//                    listener.onSuccess(response.body());
//                else
//                    listener.onFalure("解析错误");
//            }
//
//            @Override
//            public void onFailure(Call<UserBean> call, Throwable t) {
//                listener.onFalure(t.toString());
//            }
//        });
    }

    @Override
    public void register(String username, String userpass, String mobilenum, String address, String comment, onRetrofitListener listener) {
        service=retrofit.create(UserService.class);
        Call<ResultBean> call=service.doRegist(username,userpass,mobilenum,address,comment);
        bindCallback(call,listener,1);
    }

    @Override
    public void getUserById(int user_id, onRetrofitListener listener) {
        service=retrofit.create(UserService.class);
        Call<UserBean> call=service.getUserById(user_id);
        bindCallback(call,listener,4);
    }

    @Override
    public void updateUserById(int user_id, String username, String userpass, String mobilenum, String address, onRetrofitListener listener) {
        service=retrofit.create(UserService.class);
        Call<ResultBean> call=service.updateUserById(user_id,username,userpass,mobilenum,address);
        bindCallback(call,listener,1);
    }
}
